/**
 * @class ExtGames.Deck
 * @param {Array} cards An array of cards to initialise the deck with
 * Represents the deck of all non-dealt cards
 */
ExtGames.GameSelectionWindow = function(config) {
  var config = config || {};  
  
  this.closeable = config.closable || true;
  
  ExtGames.GameSelectionWindow.superclass.constructor.call(this, config);      
};

Ext.extend(ExtGames.GameSelectionWindow, Ext.Window, {
	
	 initComponent:function() {
		 
		 var games = [
		 	'May I',
		 	'Uno',
		 	'Flinch'
		 ];
		 
		 var selectionBox = {
		 	id: 'gameSelectionBox',
			xtype:'combo',
			fieldLabel: 'Game',
			editable: true,
			triggerAction: 'all',
			allowBlank: false,
			minChars: 9999,
			emptyText: 'Select a Game',
			fieldLabel:'Combo 1',
			store: games
		 };
		 
		 var decksSelection =  new Ext.form.NumberField({
		 	id: 'decksSelectionField',
		 	xtype: 'textfield',
		 	width: 30,
		 	allowBlank: false,
		 	value: 2,
		 	minValue: 1,
		 	maxValue: 10,
		 	name: 'decks',
		 	fieldLabel: '# of Decks'
		 });
		 
		 var jokerSelection =  new Ext.form.NumberField({
		 	id: 'jokerSelectionField',
		 	xtype: 'textfield',
		 	width: 30,
		 	allowBlank: false,
		 	value: 2,
		 	minValue: 0,
		 	maxValue: 52,
		 	name: 'jokers',
		 	fieldLabel: 'Jokers per Deck'
		 });

		 var submitButton = {
		 	text: 'Submit',
		 	 formBind:true,
		 	scope: this,
		 	handler: this.submit
		 };
		 
		 this.formPanel = new Ext.form.FormPanel({
		 	cls: 'game-selection',
		 	monitorValid:true,
		 	items: [
			 	selectionBox,
			 	decksSelection,
			 	jokerSelection
			 ],
			 buttons: [
			 	submitButton
			 ]
		 });
		 
		 var config = {
			 title: 'Game Selection',
			 width: 500,
			 height: 300,
			 items: [
			 	this.formPanel
			 ]
		 }; // eo config object
		  
		 // apply config
		 Ext.apply(this, Ext.apply(this.initialConfig, config));
		  
		 // call parent
		 ExtGames.GameSelectionWindow.superclass.initComponent.apply(this, arguments);
		 
	 },
	 
	 submit: function() {
	 	var sel = Ext.getCmp('gameSelectionBox').value;
	 	var decks = Ext.getCmp('decksSelectionField').value;
	 	var jokers = Ext.getCmp('jokerSelectionField').value;
	 	
	 	if (!sel) {
	 		return;
	 	}
	 		 	
	 	if (sel == 'May I') {
	 		util = new ExtGames.MayIHangoutUtil();
		 	
		 	var pack = new ExtGames.Pack({
				decks: decks,
				jokers: jokers
			});
			
			util.initialSetup(pack);
	    }
	    else if (sel == 'Uno') {
	    	util = new ExtGames.UnoHangoutUtil();
		 	
		 	var pack = new ExtGames.Pack({
				decks: decks,
				jokers: jokers
			});
			
			util.initialSetup(pack);
	    }
	 	
	    else if (sel == 'Flinch') {
	    	util = new ExtGames.FlinchHangoutUtil();
		 	
		 	var pack = new ExtGames.Pack({
				decks: decks,
				jokers: jokers
			});
			
			util.initialSetup(pack);
	    }
	 }
  
});